package com.xiaoyu.lanling.feature.user.options

import android.content.Context
import androidx.appcompat.app.AlertDialog
import com.xiaoyu.im.provider.ChatIdMapper
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.user.data.UserInfoData

class SubscribeAction(context: Context, val requestTag: Any, private val targetUid: String, private val subscribe: Boolean) : MoreActionItemBase(context) {

    private val chatId: String? = ChatIdMapper.getInstance().getChatIdByUid(targetUid)

    override val title: CharSequence
        get() = mContext.getString(if (subscribe) R.string.user_more_action_unsubscribe else R.string.user_more_action_subscribe)

    override fun onClick() {
        if (subscribe) {
            showUnsubscribeDialog()
        } else {
            UserInfoData.subscribeUser(requestTag, targetUid, true)
        }
    }

    private fun showUnsubscribeDialog() {
        AlertDialog.Builder(mContext)
                .setMessage(mContext.getString(R.string.user_unsubscribe_dialog_message))
                .setPositiveButton(R.string.action_confirm) { _, _ -> UserInfoData.subscribeUser(requestTag, targetUid, false) }
                .setNegativeButton(R.string.action_cancel) { _, _ -> }
                .show()
    }
}